<%@ page import="com.cinsea.report.model.Reportfield" %>
<%@ page import="com.cinsea.form.model.Formfield" %>
<%@ page import="com.cinsea.report.service.ReportfieldService" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@include file="/common/common.jsp" %>

<head>
<%@include file="/common/head.jsp" %>
<script src='/dwr/interface/DataService.js'></script>
<script src='/dwr/interface/OptionService.js'></script>
<script src='/dwr/util.js'></script>
<script type="text/javascript">
    var store;
    var selected=new Array();
    var dlg0;
   var viewport=null;


    <!--页面菜单开始-->

    Ext.onReady(function(){

       var tb = new Ext.Toolbar({id:'toolbar1'});
       tb.render('pagemenubar');
       addBtn(tb,'快捷搜索','S','zoom',function(){onSearch2()});addBtn(tb,'清空条件','R','erase',function(){reset()});addBtn(tb,'高级搜索','G','zoom',function(){onSearch3()});addBtn(tb,'新增','D','add',function(){onUrl('/workflow/wfprocess.jsp?workflowid=40895a003614243d0136155ccd6901ab','新增')});
        //tb.add('->');
        tb.add(pagemenutable);


        function clearAllSelectedCheckbox(){
            var hd = Ext.fly(grid.getView().innerHd).child('div.x-grid3-hd-checker');
            hd.removeClass('x-grid3-hd-checker-on');
            grid.getSelectionModel().clearSelections();
        }
    store = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '/reportdata.do?&isnew=null&action=search&reportid=402881e43616a5f2013616d7149c004f&savedqueryid=&isjson=1&pagesize=20'
        }),
        reader: new Ext.data.JsonReader({
            sql1:'sql1',
            sql2:'sql2',
            root: 'result',
            totalProperty: 'totalCount',

             fields: ['processid','shiyou','meetingroom','jieshuriqi','meetingtime','jiesushijian','submitren','canjialingdao','zhubanbm']

        }),

        remoteSort: true
    });
    //store.setDefaultSort('id', 'desc');

    var sm=new Ext.grid.RowSelectionModel({selectRow:Ext.emptyFn});

          var cm = new Ext.grid.ColumnModel([{header:'会议名称',dataIndex:'shiyou',width:0,sortable:false},{header:'会议室',dataIndex:'meetingroom',width:0,sortable:false},{header:'会议日期',dataIndex:'jieshuriqi',width:0,sortable:true},{header:'会议开始时间',dataIndex:'meetingtime',width:0,sortable:false},{header:'会议结束时间',dataIndex:'jiesushijian',width:0,sortable:false},{header:'申请人',dataIndex:'submitren',width:0,sortable:false},{header:'参加领导',dataIndex:'canjialingdao',width:0,sortable:false},{header:'主办部门',dataIndex:'zhubanbm',width:0,sortable:false}]);


   // cm.defaultSortable = true;

                    var autorefresh=new Ext.ux.grid.AutoRefresher({ interval:'5'})
                   var grid = new Ext.grid.GridPanel({
                       region: 'center',
                       store: store,
                       cm: cm,
                       trackMouseOver:false,
                       sm:sm ,
                       loadMask: true,
                       viewConfig: {

                             forceFit:true,

                           enableRowBody:true,
                           sortAscText:'升序',
                           sortDescText:'降序',
                           columnsText:'列定义',
                           getRowClass : function(record, rowIndex, p, store){
                               return 'x-grid3-row-collapsed';
                           }
                       },
                       bbar: new Ext.PagingToolbar({
                           pageSize: 20,

            store: store,
            displayInfo: true,
            beforePageText:'第',
            afterPageText:'页\/{0}',
            firstText:'第一页',
            prevText:'上页',
            nextText:'下页',
            lastText:'最后页',
            displayMsg:'显示 {0} - {1}条记录 \/ {2}',
            emptyMsg:'没有结果返回'
        })
    });

    store.baseParams={}
     store.baseParams.datastatus='';

        store.on('load', function(st, recs) {
            Ext.getDom('sqlstr1').value=st.reader.jsonData.sql1;
            Ext.getDom('sqlstr2').value=st.reader.jsonData.sql2;
        });

    //Viewport
    //ie6 bug
    Ext.get('divSearch').setVisible(true);
	viewport = new Ext.Viewport({

        layout: 'border',
        items: [{region:'north',autoScroll:true,contentEl:'divSearch',split:true,collapseMode:'mini'},grid]
	});
    var optstore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [
            ['0','新建模板'],
            ['1','原有模板']
        ]
    });
    var templatestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : []
    });
    var typestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [
            ['1','公共'],
            ['0','私有']
        ]
    });
    var yesorno = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [
            ['1','是'],
            ['0','否']
        ]
    });
    mainform1 = new Ext.FormPanel({
        region:'center',
        id:'mainform1',
        frame:true,
        labelWidth :150,
        autoScroll:true,
        items :[
            {
                xtype:'hidden',
                name: 'reportid',
                value:'402881e43616a5f2013616d7149c004f'
            } ,
            {   fieldLabel:"操作类型",
                xtype:'combo',
                typeAhead: true,
                forceSelection:true,
                value:'0',
                mode:'local',
                triggerAction: 'all',
                store:optstore,
                valueField:'value',
                displayField:'text',
                hiddenName: 'opttype',
                name: 'opttype',
                listeners:{
                            'select':function(f, r, i) {
                                if (i == 0) {
                                    showField(mainform1.form.findField('objname'));
                                    showField(mainform1.form.findField('bepublic'));
                                    showField(mainform1.form.findField('objorder'));
                                    hideField(mainform1.form.findField('templateid'));
                                }
                                else if(i==1){
                                    hideField(mainform1.form.findField('objname'));
                                    hideField(mainform1.form.findField('bepublic'));
                                    hideField(mainform1.form.findField('objorder'));
                                    showField(mainform1.form.findField('templateid'));
                                }
                            }
                        }
            } ,
            {   fieldLabel:"模板",
                xtype:'combo',
                typeAhead: true,
                forceSelection:true,
                mode:'local',
                triggerAction: 'all',
                store:templatestore,
                valueField:'value',
                displayField:'text',
                hiddenName: 'templateid',
                name: 'templateid'
            } ,
            {   fieldLabel:"查询名称",
                allowBlank:false,
                blankText:'必填项不能为空',
                xtype:'textfield',
                name: 'objname'
            } ,
            {   fieldLabel:"查询类型",
                xtype:'combo',
                typeAhead: true,
                forceSelection:true,
                value:'0',
                mode:'local',
                triggerAction: 'all',
                store:typestore,
                valueField:'value',
                displayField:'text',
                hiddenName: 'bepublic',
                name: 'bepublic'
            } ,
            {   fieldLabel:"顺序",
                xtype:'textfield',
                maskRe : /^\d$/,
                name: 'objorder'
            }
        ]
    });
    formwin = new Ext.Window({
        title:'查询信息',
        layout:'border',
        closeAction:'hide',
        plain: true,
        modal :true,
        width:viewport.getSize().width * 0.4,
        height:viewport.getSize().height * 0.4,
        buttons: [
            {text     : '保存',
                handler  : function() {
                    var o = $('#mainForm').serializeArray();
                    var data = {};
                    for (var i = 0; i < o.length; i++) {
                        if (o[i].value != null && o[i].value != "") {
                            data[o[i].name] = o[i].value;
                        }
                    }
                    mainform1.form.submit({
                        url:'/reportdata.do?&isnew=null&action=search&reportid=402881e43616a5f2013616d7149c004f&savedqueryid=&savequerytemplate=true',
                        params:data ,
                        success:function(f, a) {
                            pop(a.result.msg);
                        },
                        failure:function(f, a) {
                            switch (a.failureType) {
                                case Ext.form.Action.CLIENT_INVALID :
                                    pop('存在未通过验证的数据!', '错误', 5, 'cross');
                                    break;
                                case Ext.form.Action.CONNECT_FAILURE :
                                    pop('连接错误!', '错误', 5, 'cross');
                                    break;
                                case Ext.form.Action.SERVER_INVALID :
                                    pop(a.result.msg, '错误', 5, 'cross');
                            }
                        }
                    });
                    formwin.hide();

                }
            },
            {
                text     : '关闭',
                handler  : function() {
                    formwin.hide();
                }

            }
        ],
        items:[mainform1]
    });
    formwin.render(Ext.getBody());
        showField(mainform1.form.findField('objname'));
        showField(mainform1.form.findField('bepublic'));
        showField(mainform1.form.findField('objorder'));
        hideField(mainform1.form.findField('templateid'));

     onSearch2();

        dlg0 = new Ext.Window({
                layout:'border',
                closeAction:'hide',
                plain: true,
                modal :true,
                width:viewport.getSize().width*0.8,
                height:viewport.getSize().height*0.8,
                buttons: [{
                    text     : '关闭',
                    handler  : function(){
                        dlg0.hide();
                    }

                }],
                items:[{
                id:'dlgpanel',
                region:'center',
                xtype     :'iframepanel',
                frameConfig: {
                    autoCreate:{id:'dlgframe', name:'dlgframe', frameborder:0} ,
                    eventsFollowFrameLinks : false
                },
                autoScroll:true
            }]
            });
});

</script>
</head>
<body style="margin:10px,10px,10px,0px;padding:0px">


<div id="divSearch" style="display:none;">
 <div id="pagemenubar"></div>
<table width="100%" id="pagemenutable" style="display:none">
         <tr>
             <td align="right">
                 <a href="javascript:saveTemplate();">保存该查询至模板</a>&nbsp;
                 <select id="contemplate" onchange="onSearch4('402881e43616a5f2013616d7149c004f')" style="width:150">
                     <option value="0">请选择</option>

                 </select>
             </td>
         </tr>
     </table>

 <!--页面菜单结束-->
     <form action="/reportdata.do?action=search&from=list&isnew=null&reportid=402881e43616a5f2013616d7149c004f" id="mainForm" name="mainForm" method="post">
     <input type="hidden" id="sqlwhere" name="sqlwhere" value=""/>
     <input type="hidden" id="sqlstr1" name="sqlstr1"/>
     <input type="hidden" id="sqlstr2" name="sqlstr2"/>
 <!--条件>

 <input type='hidden' name="sqlwhere" id="sqlwhere" value="">
 <input type='hidden' name="initquerystr" id="initquerystr" value="">

 <!--  ***************************************************************************************************************************-->


   <table id="myTable" class="formtable">

 <tr>

     <td  class="formlabel" width=10% nowrap>

         申请部门
     <td width=15% class='formvalue'>

<button  class=Browser type=button onclick="getBrowser('conut_meetingapp_submitdep_value','conut_meetingapp_submitdepspan','6','/hrm/orgview.jsp?id=','0');"></button>

<input type="hidden" id="conut_meetingapp_submitdep_value" name="conut_meetingapp_submitdep_value" value=""    >

<span id="conut_meetingapp_submitdepspan" name="conut_meetingapp_submitdepspan" ></span>

<input  type="checkbox" name="conut_meetingapp_submitdep_checkbox" value="1" ></td>
     <td  class="formlabel" width=10% nowrap>

         会议室
     <td width=15% class='formvalue'>

<button  class=Browser type=button onclick="getBrowser('conut_meetingapp_meetingroom_value','conut_meetingapp_meetingroomspan','40895a003614243d01361557937901a9','/form/formprocess.jsp?processid=','0');"></button>

<input type="hidden" id="conut_meetingapp_meetingroom_value" name="conut_meetingapp_meetingroom_value" value=""    >

<span id="conut_meetingapp_meetingroomspan" name="conut_meetingapp_meetingroomspan" ></span>

</td>
     <td  class="formlabel" width=10% nowrap>

         编号

     <td  class="formvalue" width=15% nowrap>
       <input type=text class=inputstyle style="width:100%" size=30 name="conut_meetingapp_serialnumber_value" value=""/><span   id="conut_meetingapp_serialnumber_valuespan"></span>
     </td>


 <tr>

     <td  class="formlabel" width=10% nowrap>

         会议名称

     <td  class="formvalue" width=15% nowrap>
       <input type=text class=inputstyle style="width:100%" size=30 name="conut_meetingapp_shiyou_value" value=""/><span   id="conut_meetingapp_shiyou_valuespan"></span>
     </td>


     <td  class="formlabel" width=10% nowrap>

         是否使用视频会议
     <input type="hidden" name="ut_meetingapp_ifnot2_fieldcheck" value="" ><td width=15% class='formvalue'>

 <select class="inputstyle2" style="width:100%" id="conut_meetingapp_ifnot2_value"  name="conut_meetingapp_ifnot2_value"  onchange="fillotherselect('402881e5360c4d6501360c68c7a30010',this,'ut_meetingapp_ifnot2',-1)">

<option value=""  selected  ></option>

<option value="402881e5360c4d6501360c68ea740011"  >是</option>

<option value="402881e5360c4d6501360c68ffc00012"  >否</option></select> <span id='conut_meetingapp_ifnot2_valuespan'></span></td>
     <td  class="formlabel" width=10% nowrap>

         是否涉及会标制作
     <input type="hidden" name="ut_meetingapp_ifnot1_fieldcheck" value="" ><td width=15% class='formvalue'>

 <select class="inputstyle2" style="width:100%" id="conut_meetingapp_ifnot1_value"  name="conut_meetingapp_ifnot1_value"  onchange="fillotherselect('402881e5360c4d6501360c68c7a30010',this,'ut_meetingapp_ifnot1',-1)">

<option value=""  selected  ></option>

<option value="402881e5360c4d6501360c68ea740011"  >是</option>

<option value="402881e5360c4d6501360c68ffc00012"  >否</option></select> <span id='conut_meetingapp_ifnot1_valuespan'></span></td>
 <tr>

     <td  class="formlabel" width=10% nowrap>

         会议日期

             <td  class="formvalue" width=15% nowrap>
                    <input type=text class=inputstyle style="width:45%" size=10 name="conut_meetingapp_jieshuriqi_value"  value="<%=DateUtil.getFirstDayOfWeek(DateUtil.getCurrentDate())%>" onclick="WdatePicker()" >
                    <span id="conut_meetingapp_jieshuriqi_valuespan"   ></span>-
                    <input type=text class=inputstyle style="width:45%" size=10 name="conut_meetingapp_jieshuriqi_value1"  value="<%=DateUtil.getLastDayOfWeek(DateUtil.getCurrentDate())%>" onclick="WdatePicker()" >
                    <span id="conut_meetingapp_jieshuriqi_value1span"  >

                    </span>

                 </td>



   </table>
 </form>
 </div>
<!-- 条件结束-->
<script type="text/javascript">
      var inputid;
      var spanid;
      var temp;
     function checkdirect(obj)
  {
      inputid=obj.id;
      spanid=obj.name;
      temp=0;
  }
      $(document).ready(function($){

         $.Autocompleter.Selection = function(field, start, end) {
             if( field.createTextRange ){
              var selRange = field.createTextRange();
              selRange.collapse(true);
              selRange.moveStart("character", start);
              selRange.moveEnd("character", end);
              selRange.select();
              if(inputid==undefined||spanid==undefined)
                 return;
               var len=field.value.indexOf("  ");
                 var lenspance=field.value.indexOf(" ");

                   if(temp==0&&len>0){
                   temp=1;
               var  length=field.value.length;

               var data=field.value;

              document.getElementById(inputid).value=field.value.substring(0,field.value.indexOf("  "));
             document.getElementById('con'+spanid+'span').innerHTML= data.substring(len,length);
                   }else if(temp==0&&lenspance>0){

                 var data=field.value;

              document.getElementById(inputid).value=data;
             document.getElementById('con'+spanid+'span').innerHTML= data;

                   }else{
                       document.getElementById(inputid).value="";
                   }
       } else if( field.setSelectionRange ){
              field.setSelectionRange(start, end);
          } else {
                 if( field.selectionStart ){
                  field.selectionStart = start;
                  field.selectionEnd = end;
              }
          }
          field.focus();
      };

       });

  </script>

  <script language="javascript" type="text/javascript">
   function onSearch(pageno){
          document.mainForm.pageno.value=pageno;
       document.mainForm.submit();
   }
   function createexcel(){
          document.mainForm.action="/reportdata.do?action=createexcel&reportid=402881e43616a5f2013616d7149c004f&exportflag=";
       document.mainForm.submit();
   }

   function onSearch2(){
        var o=$('#mainForm').serializeArray();
       var data={};
       for(var i=0;i<o.length;i++) {
           if(o[i].value!=null&&o[i].value!=""){
           data[o[i].name]=o[i].value;
           }
       }
     checkfields='';
    checkmessage="必填项不能为空";
    if(checkForm(mainForm,checkfields,checkmessage)){


	   		 store.baseParams=data;
        store.baseParams.datastatus='';
       store.load({params:{start:0, limit:20}});
	  }
   }
   $(document).keydown(function(event) {
       if (event.keyCode == 13) {
          onSearch2();
       }
   });

   function onSearch3(){
          document.getElementById('mainForm').action="/report/reportsearch.jsp?reportid=402881e43616a5f2013616d7149c004f";
       document.getElementById('mainForm').submit();
   }
   function reset(){
         $('#mainForm span').text('');
         $('#mainForm input[type=text]').val('');
         $('#mainForm textarea').val('');
         $('#mainForm input[type=checkbox]').each(function(){
             this.checked=false;
         });
         $('#mainForm input[type=hidden]').each(function(){
             if(this.name.indexOf('con')==0)
             this.value='';
         });
         $('#mainForm select').val('');
         $('#mainForm span[fillin=1]').each(function(){
             this.innerHTML='<img src=/images/base/checkinput.gif>';
         });
   }

   function fillotherselect(selectid,elementobj, fieldid, rowindex) {
           var elementvalue = Trim(getValidStr(elementobj.value));//选择项的值
           var objname = "" + fieldid + "_fieldcheck";
           var fieldcheck = Trim(getValidStr(document.getElementById(objname).value));//用于保存选择项子项的值(formfieldid)
           if (fieldcheck == "")
               return;
           OptionService.getOptions(selectid,elementvalue,{
         callback:function(dataFromServer) {
           createList(selectid,dataFromServer, fieldcheck,rowindex);
         }
       });
       }
       function createList(selectid,data, fieldcheck, rowindex)
       {
           var select_array = fieldcheck.split(",");
           for (loop = 0; loop < select_array.length; loop++) {
               var objname = "con" + select_array[loop] + "_value";
               if (rowindex != -1)
                   objname += "_" + rowindex;

               if (document.getElementById(objname) == null) {
                   return;
               }
               dwr.util.removeAllOptions(objname);
               dwr.util.addOptions(objname, data,"id","objname");
               fillotherselect(selectid,document.getElementById(objname), select_array[loop], rowindex);
           }
       }

  function getBrowser(inputname,inputspan,browserid,viewurl,isneed){

	var idsin = document.getElementsByName(inputname)[0].value;
	var id;
    try{
         var url ='/browser/browser.jsp?id='+browserid+'&idsin='+idsin;
            if (idsin.length > 900) {   //当idsin过长时，ie的url不支持过长的地址
                url ='/browser/browser.jsp?id='+browserid;
            }
    id=showDialog(url);
    }catch(e){return}
    if (id!=null) {

    if (id[0] != '0') {
		document.getElementById(inputname).value = id[0];
		document.getElementById(inputspan).innerHTML = id[1];

    }else{
		document.getElementById(inputname).value = '';
		if (isneed=='0')
		document.getElementById(inputspan).innerHTML = '';
		else
		document.getElementById(inputspan).innerHTML = '<img src=/images/base/checkinput.gif>';

            }
         }
    }


   function delone(processid)
   {
       var processid=processid

     Ext.MessageBox.confirm('', '确认删除该记录吗(Y\/N)?', function (btn, text) {
             if (btn == 'yes') {
                 Ext.Ajax.request({
                     url: '/reportdata.do?action=delone',
                     params:{processid:processid,reportid:'402881e43616a5f2013616d7149c004f'},
                     success: function(res) {
                        if(res.responseText == 'noright')
                         {
                           Ext.MessageBox.alert('', '未授权的操作',function(){

                            }) ;
                         }else{
                         selected = [];
                          store.baseParams={}
                         store.baseParams.datastatus='';
                         store.load({params:{start:0, limit:20}});
                         }
                     }
                 });
             }
         });
   }
     function onDelete()
     {
         if (selected.length == 0) {
             Ext.MessageBox.alert('', '请选择！');
             return;
         }

         Ext.MessageBox.confirm('', '确认删除该记录吗(Y\/N)?', function (btn, text) {

             if (btn =='yes') {
                 Ext.Ajax.request({
                     url: '/reportdata.do?action=delete',
                     params:{ids:selected.toString(),reportid:'402881e43616a5f2013616d7149c004f',datastatus:''},
                     success: function(res) {
                         if(res.responseText == 'noright')
                         {
                           Ext.MessageBox.alert('', '未授权的操作',function(){

                            }) ;
                         }else{
                         selected = [];
                          store.baseParams={}
                         store.baseParams.datastatus='';
                         store.load({params:{start:0, limit:20}});
                         }
                     }
                 });
             }
         });

     }
   function datasearch(value){
       var isdatastatus=value;
     location.href="/reportdata.do?&isnew=null&action=search&reportid=402881e43616a5f2013616d7149c004f&savedqueryid=&isdatastatus="+isdatastatus+"&datastatus="+value;
   }
   function onSearch4(reportid){
       var savedqueryid=document.getElementById("contemplate").value;
          location.href="/reportdata.do?&isnew=null&action=search&reportid=402881e43616a5f2013616d7149c004f&savedqueryid="+savedqueryid;
   }
   function searchOperate(){
       var searchOperate=document.getElementById("searchOperate");
       if(searchOperate.value=="0"){
           document.getElementById("objnametr").style.display="block";
           document.getElementById("publictr").style.display="block";
           document.getElementById("objdesctr").style.display="block";
           document.getElementById("mycontemplate").style.display="none";
       }else{
           document.getElementById("objnametr").style.display="none";
           document.getElementById("publictr").style.display="none";
           document.getElementById("objdesctr").style.display="none";
           document.getElementById("mycontemplate").style.display="block";
       }
   }
   function openchild(url)
  {
    this.dlg0.getComponent('dlgpanel').setSrc(""+url);
    this.dlg0.show();
  }


   function saveTemplate(){
        this.formwin.show()
 }


      function exportExcel(){
          document.forms[0].action="/excelupload.do?reportid=402881e43616a5f2013616d7149c004f&action=reportExport&savedqueryid=";
          document.forms[0].submit();
      }
 function gray(obj)
{
switch(obj.flag)
{
//当flag为0时,为未选中状态
case '0':obj.checked=true;obj.indeterminate=true;obj.flag='2';
      obj.value='2';
    break;
//当flag未1时,为白色选中状态
case '2':obj.checked=true;obj.indeterminate=false;obj.flag='1';
        obj.value='1';
    break;
//当flag为2时,为灰色选中状态  (找出所有的数据)
case '1':obj.checked=false;obj.indeterminate=false;obj.flag='0';
    obj.value='0';
    break;
}
}
  function showtemplate(){
      onUrl('/report/querytemplatelist.jsp?reportid=402881e43616a5f2013616d7149c004f','模板管理')

}
   </script>
<script>
    Ext.onReady(function () {
        toolbar = Ext.getCmp('toolbar1');
        toolbar.addFill();
        var refreshbtn = new Ext.Button({
            text:'刷新',
            iconCls :Ext.ux.iconMgr.getIcon('reload'),
            handler:function () {
                    onSearch2();
            }
        });
        toolbar.add(refreshbtn);
    })
</script>
<script type="text/javascript" language="javascript" src="/datapicker/WdatePicker.js"></script>
  </body>
</html>